import moment from 'dayjs'
import { BasicColumn, FormSchema } from "/@/components/Table";
import { render } from "/@/utils/common/renderUtils";
import { text } from 'stream/consumers';

//订单列表 - 状态转译
const statusFmt = ({text}: { text: any }) => {
  if (!text) {
    return
  }
  var stateText = '';
  if (text == '0') {
    stateText = '待审'
  } else if (text == '1') {
    stateText = '已审'
  } else if (text == '2') {
    stateText = '取消'
  } 
  const color = text == '0' ? 'green' : text == '1' ? 'red' : 'gray';
  return render.renderTag(stateText, color)
}

//订单列表 - 会员类型转译
const typeFmt = ({text, record}) => {
  if (!text || !record.state) {
    return text
  }
  const color = text == '1' ? 'red' : text == '2' ? 'blue' : 'green';
  return render.renderTag(render.renderDict(text, 'memberType'), color)
}

//订单列表 - 关联账号
const userCodeFmt = ({text, record}) => {
  if (!text) {
    return
  }
  if (record.type == "1") {
    return
  } 
  if (record.sysRealName) {
    text = record.sysRealName + "（" + record.sysUserName + "）";
  } 
  return text;
}

//订单列表 - 关联账号
const corpNameFmt = ({text, record}) => {
  if (!text && record.state) {
    return "未匹配客户单位"
  } else {
    return text;
  }
}

// 订单列表 - 表头
export const columns: BasicColumn[] = [
  { dataIndex: "state", title: "状态", width: 30, align: "center", customRender: statusFmt, },
  { dataIndex: "name", title: "姓名", width: 70, align: "left", slots: { customRender: 'name'  } },
  { dataIndex: "tel", title: "电话", width: 65, align: "center", slots: { customRender: 'tel'  }  },
  { dataIndex: "corpName", title: "单位名称", width: 100, align: "left", customRender: corpNameFmt, ellipsis: true},
  { dataIndex: "departName", title: "部门", width: 40, align: "left" },
  { dataIndex: "type", title: "类型", width: 30, align: "center", customRender: typeFmt, },
  { dataIndex: "userCode", title: "客服账号", width: 40, align: "right", customRender: userCodeFmt, },
  { dataIndex: "inviteName", title: "邀请人", width: 40, align: "center" },
  { dataIndex: "approvaler", title: "审核人", width: 40, align: "center" },
  { dataIndex: "createDate", title: "注册时间", width: 50, align: "center" },
  { dataIndex: "approvalDate", title: "审核时间", width: 50, align: "center" },
  { dataIndex: "loginDate", title: "登录时间", width: 50, align: "center" },
]